class Solution
{
public:
    int sumSubseqWidths(vector<int> &nums)
    {
        int n = nums.size();
        sort(nums.begin(), nums.end());
        long long result = 0LL;
        vector<long long> pow2(n + 1);
        pow2[0] = 1;
        for (int i = 1; i <= n; ++i)
        {
            pow2[i] = 2 * pow2[i - 1];
            pow2[i] %= 1000000007;
        }
        for (long long i = 0; i < n; ++i)
        {
            result += nums[i] * pow2[i];
            result -= nums[i] * pow2[n - i - 1];
            result %= 1000000007;
        }
        return result;
    }
};